/***************************************************************************
 *   Copyright (C) 2007 by vasaka,,,   *
 *   gorinich.zmey at gmail   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "rng.h"
#include <SDL/SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include "../randozavr.h"
#include "bitmapimage.h"            

using namespace BitmapFiles;   

//parameters - think about getting them from command line
int Scale_g=16; 

//load image gets pointer to external image array its dimensions color mask and color bits
void ConvertImage ( int* img1_,int* img2_,int width_,int height_,int scale=16 )
{
  printf("starting image to claster format switching\n");
  Randozavr<short> Rndayzer_(0);  
  Rndayzer_ = Randozavr<short>(scale*scale);
    
  for ( int x = 0; x < width_; x++ )
    for ( int y = 0; y < height_; y++ )
    {
      int rValue_ = img1_[x+width_*y];    
      Rndayzer_.RandomizeN(rValue_);

      for ( int i=0;i< scale*scale;i++ )
      {
        int localx = Rndayzer_[i];
        int localy = Rndayzer_[i];
        img2_[(x*scale + localx) + (y*scale +localy)*width_*scale] = i<rValue_ ? 1 : 0 ;  
      }
    }
  printf("image filled\n");
}

int main(int argc, char *argv[])
{
  if (argc<2) 
  {
    printf("Give me filename please\n");
    printf("Usage:\n");
    printf("%s input.bmp output.bmp [factor]\n", argv[0]);
    return 0;
  }
  if (argc>3)  Scale_g = std::atoi(argv[3]);
  
  /*
  SDL_Surface *screen = SDL_SetVideoMode ( 100,100,32, SDL_SWSURFACE );
  SDL_Surface *pictFF = SDL_LoadBMP ( argv[1] );   
  SDL_Surface *pict = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, pictFF->w*Scale_g,pictFF->h*Scale_g,32,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,screen->format->Amask);
  ConvertImage ( (int*)pictFF->pixels,(int*)pict->pixels,pictFF->w,pictFF->h,Scale_g );
  SDL_SaveBMP(pict,argv[1]);*/
  RBG24bit pic(argv[1]);   
  return 0;
}

